package com.niit.order.web;

import com.niit.feign.clients.UserClient;
import com.niit.feign.pojo.User;
import com.niit.order.pojo.Order;
import com.niit.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/feign")
public class FeignConsumerController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserClient userClient;

    @GetMapping("/order/{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) {
        // 根据id查询订单并返回
        Order order = orderService.queryOrderById(orderId);
       // 使用Feign 封装的客户端
        User forObject = userClient.findUserById(order.getUserId()+"");
        //封装返回的数据
        order.setUser(forObject);
        return order;
    }

    @GetMapping("/order/request")
    public String requestParamDemo(@RequestParam String param){
        return userClient.requestParam(param);
    }

    @GetMapping("/order/header")
    public User headerInfo(@RequestHeader String name,@RequestHeader String address){
        return userClient.headerInfo(name,address);
    }

    @GetMapping("/order/body")
    public String bodyInfo(@RequestBody User user){
        return userClient.bodyInfo(user);
    }

}
